﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//------------//
using QLKTX1._0.DTO;
using QLKTX1._0.DB;
using System.Data.SqlClient;
using System.Data;
namespace QLKTX1._0.DAO
{
    class HienTrangPhongDAO
    {
        public static List<HienTrangPhongDTO> dsHienTrangPhong()
        {
            List<HienTrangPhongDTO> dsHienTrangPhong = new List<HienTrangPhongDTO>();

            ConnectDB con = new ConnectDB();
            DataTable dt = con.getDataTable("SELECT * FROM hienTrang_Phong");

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                HienTrangPhongDTO hienTrangPhong = new HienTrangPhongDTO();

                hienTrangPhong.MaHienTrang  = Int32.Parse (dt.Rows[i]["maHienTrang"].ToString());

                hienTrangPhong.TenHienTrang = dt.Rows[i]["tenHienTrang"].ToString();

                // KhuDTO k = new KhuDTO(dt.Rows[i]["maKhu"].ToString(), dt.Rows[i]["tenKhu"].ToString());

                dsHienTrangPhong.Add(hienTrangPhong);
            }
            return dsHienTrangPhong;

        }
        // Ham Insert 
        public static bool themHienTrangPhong(HienTrangPhongDTO hienTrangPhong)
        {

            ConnectDB con = new ConnectDB();// dung DB

            return con.executeQuery("INSERT INTO hienTrang_Phong(tenHienTrang) VALUES(N'" + hienTrangPhong .TenHienTrang  + "')");

        }
        //Ham delete
        public static bool xoaHienTrangPhong(HienTrangPhongDTO hienTrangPhong)
        {
            ConnectDB con = new ConnectDB();

            return con.executeQuery("DELETE FROM hienTrang_Phong WHERE maHienTrang='" + hienTrangPhong.MaHienTrang + "'");
        }
        //ham update
        public static bool capNhatHienTrangPhong(HienTrangPhongDTO hienTrangPhong)
        {
            ConnectDB con = new ConnectDB();

            return con.executeQuery("UPDATE hienTrang_Phong set tenHienTrang=N'" + hienTrangPhong.TenHienTrang + "' WHERE maHienTrang='" + hienTrangPhong.MaHienTrang + "'");
        }
                
    }
}
